<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>栽培管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <script src="/static/layuimini/js/jquery.min.js"></script>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>栽培管理</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">品种名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="zhongMing" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">年份</label>
                            <div class="layui-input-inline">
                                <input type="text" name="nianFen" autocomplete="off" class="layui-input" >
                            </div>
<!--                            <label class="layui-form-label">年份</label>-->
<!--                            <div class="layui-input-inline">-->
<!--                                <input type="text" name="nianFen" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">-->
<!--                            </div>-->

                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" style="display: none;"  id="test2"></button>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container" id="gongju">
                <!--                <a th:if="${session.user.realname}" ><span th:text="${session.user.realname}"/></a>-->
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="deleteSelect">删除选中行数据</button>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="upload" id="test1"><i class="layui-icon">&#xe67c;</i>导入</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar" aria-invalid="gongju1">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>
        <script>

        </script>

    </div>
</div>
<script src="../lib/layui-v/layui.js" charset="utf-8"></script>
<script>




    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;



        var username = null;
        $.ajax({
            url: '/tAdmins/findByUser',
            type: 'post',
            success: function (data) {
                if (data.msg != 1) {
                    layer.msg("登录过期请重新登录", {icon: 5});
                    window.self.location = "/";
                    return;
                }else{
                    username=data.belongToAccount;
                }
            }
        })

        //表格界面
        table.render({
            elem: '#currentTableId',
            url: '/tZpcjsjs/findByPage',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                icon: 'layui-icon-tips'
            }]
            ,title:"栽培采集数据表"
            ,id:"id"
            ,cols: [[
                {type: 'checkbox', fixed: 'left',align:'center'}
                // ,{field:'custId', title:'ID', width:'10%', fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                ,{field:'nianFen', title:'年份', width:'10%' , sort: true ,fixed: 'left'}
                // ,{field:'email', title:'邮箱', width:150, edit: 'text', templet: function(res){
                //         return '<em>'+ res.email +'</em>'
                //     }}
                ,{field:'hangHao', title:'行号', width:'10%', sort: true, fixed: 'left',totalRow: true}
                ,{field:'zhongMing', title:'品种（系）名称杂交组合', width:'20%', fixed: 'left',  sort: true}

                ,{field:'laiYuan', title:'来源', width:'15%', sort: true, totalRow: true}
                ,{field:'changDu', title:'长度', width:'15%',  sort: true}
                ,{field:'biQiang', title:'比强', width:'15%',  sort: true}
                ,{field:'maZhi', title:'马值', width:'15%',  sort: true}
                ,{field:'lingZhong', title:'铃重', width:'15%',  sort: true}
                ,{field:'yiFen', title:'衣分', width:'15%',  sort: true}
                ,{field:'chuMiaoQi', title:'出苗期', width:'15%',  sort: true}
                ,{field:'kaiHuaQi', title:'开花期', width:'15%',  sort: true}
                ,{field:'tuXuQi', title:'吐絮期', width:'15%',  sort: true}
                ,{field:'szsMiaoQi', title:'生长势--苗期', width:'15%',  sort: true}
                ,{field:'szsHuaQi', title:'生长势--花期', width:'15%',  sort: true}
                ,{field:'zqdMiaoQi', title:'整齐度--苗期', width:'15%',  sort: true}
                ,{field:'zqdHuaQi', title:'整齐度--花期', width:'15%',  sort: true}
                ,{field:'shouHuoZhuShu', title:'收获株数', width:'15%',  sort: true}
                ,{field:'zytxZhuXing', title:'主要特征特性--株型', width:'15%',  sort: true}
                ,{field:'zytxYeXing', title:'主要特征特性--叶型', width:'15%',  sort: true}
                ,{field:'zytxLingXing', title:'主要特征特性--铃型', width:'15%',  sort: true}
                ,{field:'zytxZhuGao', title:'主要特征特性--株高', width:'15%',  sort: true}
                ,{field:'zytxJieLingXing', title:'主要特征特性--结铃性', width:'15%',  sort: true}
                ,{field:'zytxYeXuXing', title:'主要特征特性--叶絮性', width:'15%',  sort: true}
                ,{field:'kuWeiBingZhi', title:'抗病性--枯萎病指', width:'15%',  sort: true}
                ,{field:'huangWeiBingZhi', title:'抗病性--黄萎病指', width:'15%',  sort: true}
                ,{field:'tianJianJueXuan', title:'田间决选', width:'15%',  sort: true}
                ,{field:'belongToAccount', title:'所属账户', width:'15%',  sort: true}
                ,{field:'mark', title:'备注', width:'15%',  sort: true}
                ,{title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]], page: true
        });


        // 文件上传
        layui.use('upload', function () {
            var upload = layui.upload;
            upload.render({
                elem: '#test2'
                ,url: '/tAdmins/excel'
                ,accept: 'file' //普通文件
                , acceptMime: '.xls,.xlsx'
                ,done: function(res){
                    //上传完毕回调
                    if (res.msg==1){
                        layer.msg("上传成功", {icon: 6});
                        table.reload('id',{
                            method:'post'
                            ,page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        })
                    }else{
                        layer.msg("上传失败", {icon: 5});
                    }

                }

            });
        });




        // $(function (){
        //     $.ajax({
        //         url: '/users/findByUser',
        //         type: 'post',
        //         success: function (data) {
        //             if (data.msg != 1) {
        //                 layer.msg("登录过期请重新登录", {icon: 5});
        //                 window.self.location = "/";
        //                 return;
        //             }else{
        //                 if (data.role!=1){
        //                     layer.msg("对不起您无权限查看", {icon: 5});
        //                 }else{
        //                 }
        //             }
        //         }
        //     })
        // })


        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            // layer.alert(result, {
            //     title: '最终的搜索信息'
            // });

            // 执行搜索重载

            table.reload('id',{
                url: '/tZpcjsjs/findByTJ'
                ,method:'post'
                ,where: {
                    'zhongMing':data.field.zhongMing,
                    'nianFen':data.field.nianFen
                }
                ,contentType: 'application/json'
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            })
            return false;

        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/addzcsj.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });

            } else if (obj.event === 'deleteSelect') {  // 监听删除操作
                var data = checkStatus.data;
                var id="";
                if(data.length > 0) {
                    for (var i=0;i<data.length;i++) {
                        id+=data[i].id+",";
                    }
                    console.log(id);
                    layer.confirm('确定删除选中的数据？', {icon: 3, title: '提示信息'}, function (index) {
                        $.post('/tZpcjsjs/deleteSelect',{"id":id},function(data){
                            if (data.msg==1){
                                layer.msg("删除成功", {icon: 6});
                                layer.close(index);
                                // 表格重载
                                table.reload('id',{
                                    page: {
                                        curr: 1 //重新从第 1 页开始
                                    }
                                })
                            }

                        });
                    })
                }else{
                    layer.msg('请选择需要删除的数据',{icon:5});
                }

            }else if(obj.event === 'upload') {
                $("#test2").click();

            }




        });
        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            if (obj.event === 'edit') {
                $.ajax({
                    url: '/tAdmins/findByUser',
                    type: 'post',
                    success: function (data) {
                        if (data.msg != 1) {
                            alert(data.msg);
                            window.parent.location.href = "/";
                            // $.messager.alert({
                            //     title:'提示',
                            //     msg:'读取数据异常：'+map.msg
                            // });
                            return;
                        }else {
                            if (data.role=="1"){
                                layer.msg("您没有权限操作", {icon: 5});

                            }else{
                                var data = obj.data;
                                var index = layer.open({
                                    title: '编辑用户',
                                    type: 2,
                                    shade: 0.2,
                                    maxmin:true,
                                    shadeClose: true,
                                    area: ['100%', '100%'],
                                    content: '../page/table/edit_zcsj.html',
                                    success: function (layero, index) {
                                        //找到它的子窗口的body
                                        let body = layer.getChildFrame('body', index);
                                        // var body = layer.getChildFrame('body', table);  //巧妙的地方在这里哦
                                        // //为子窗口元素赋值
                                        body.contents().find("#id").val(data.id);
                                        body.contents().find("#nianFen").val(data.nianFen);
                                        body.contents().find("#hangHao").val(data.hangHao);
                                        body.contents().find("#belongToAccount").val(data.belongToAccount);
                                        body.contents().find("#zhongMing").val(data.zhongMing);
                                        body.contents().find("#laiYuan").val(data.laiYuan);
                                        body.contents().find("#changDu").val(data.changDu);
                                        body.contents().find("#biQiang").val(data.biQiang);
                                        body.contents().find("#maZhi").val(data.maZhi);
                                        body.contents().find("#lingZhong").val(data.lingZhong);
                                        body.contents().find("#yiFen").val(data.yiFen);
                                        body.contents().find("#chuMiaoQi").val(data.chuMiaoQi);
                                        body.contents().find("#kaiHuaQi").val(data.kaiHuaQi);
                                        body.contents().find("#tuXuQi").val(data.tuXuQi);
                                        body.contents().find("#szsMiaoQi").val(data.szsMiaoQi);
                                        body.contents().find("#szsHuaQi").val(data.szsHuaQi);
                                        body.contents().find("#zqdMiaoQi").val(data.zqdMiaoQi);
                                        body.contents().find("#zqdHuaQi").val(data.zqdHuaQi);
                                        body.contents().find("#shouHuoZhuShu").val(data.shouHuoZhuShu);
                                        body.contents().find("#zytxZhuXing").val(data.zytxZhuXing);
                                        body.contents().find("#zytxYeXing").val(data.zytxYeXing);
                                        body.contents().find("#zytxLingXing").val(data.zytxLingXing);
                                        body.contents().find("#zytxZhuGao").val(data.zytxZhuGao);
                                        body.contents().find("#zytxJieLingXing").val(data.zytxJieLingXing);
                                        body.contents().find("#zytxYeXuXing").val(data.zytxYeXuXing);
                                        body.contents().find("#kuWeiBingZhi").val(data.kuWeiBingZhi);
                                        body.contents().find("#huangWeiBingZhi").val(data.huangWeiBingZhi);
                                        body.contents().find("#tianJianJueXuan").val(data.tianJianJueXuan);
                                        body.contents().find("#mark").val(data.mark);
                                    }
                                });
                                $(window).on("resize", function () {
                                    layer.full(index);
                                });
                                return false;
                            }
                        }
                    }
                })

            } else if (obj.event === 'delete') {

                $.ajax({
                    url: '/tAdmins/findByUser',
                    type: 'post',
                    success: function (data) {
                        if (data.msg != 1) {
                            alert(data.msg);
                            window.parent.location.href = "/";
                            // $.messager.alert({
                            //     title:'提示',
                            //     msg:'读取数据异常：'+map.msg
                            // });
                            return;
                        }else {
                            if (data.role=="1"){
                                layer.msg("您没有权限操作", {icon: 5});
                            }else {
                                var data = obj.data;
                                var d = {"id": data.id};
                                var datas = JSON.stringify(d);
                                layer.confirm('真的删除行么',{icon:3, title:'提示信息'}, function (index) {
                                    $.ajax({
                                        url: "/tZpcjsjs/delete",
                                        type: 'post',
                                        data: datas,
                                        contentType: "application/json;charset=utf-8",
                                        dataType: 'json',
                                        async: false,//false为同步，这个Ajax请求将整个浏览器锁死
                                        success: function (data) {
                                            if (data.msg == 1) {
                                                //删除这一行
                                                obj.del();
                                                //关闭弹框
                                                layer.close(index);
                                                layer.msg("删除成功", {icon: 6});
                                            } else {
                                                layer.msg("删除失败", {icon: 5});
                                            }
                                        }
                                    });
                                    return false;
                                });
                            }
                        }
                    }
                })

            }
        });


    });
</script>

</body>
</html>